Skip to content

Re-export used units (uses export) and project-wide uses (--project-uses) - #6

Open
civilian7 wants to merge 1 commit into
Moonbot-Tech:mainfrom
civilian7:feat/uses-export
Open

civilian7 wants to merge 1 commit into
Moonbot-Tech:mainfrom
civilian7:feat/uses-export

Conversation

@civilian7

Copy link
Copy Markdown

Summary

Two additions to unit handling, for applications built on a set of library units:

  • uses export (unleashed mode): a unit passes units of its interface uses clause on to the units that use it, so one name brings a whole set (C# global using, Rust pub use, TypeScript export *).
  • --project-uses=A,B: every unit and program of the run uses A and B, as if they stood first in its uses clause. -Fa only covers programs.
unit Lumi;
interface
uses export UI.Forms, UI.StdCtrls, UI.Grids, Data.Window;
end.

program Orders;
uses Lumi;   { TForm, TButton, TGrid, TDataWindow }

Semantics

  • export right after uses covers the clause; before a later unit, that unit only. In the implementation uses clause it is an error (03448).
  • The passed-on units are visible as if they stood right before the re-exporting unit: its own names win, later units of the user win over both, every passed-on unit stays reachable by its qualified name. Transitive. Naming a passed-on unit again is no duplicate.
  • The user records the passed-on units as used units, so their crc goes into its ppu and a change of their interface recompiles it, although it names only the re-exporting unit.
  • No "unit not used" hint for a unit used only for what it passes on, nor for the passed-on units inside the re-exporting unit.
  • --project-uses: a unit that is one of the listed units does not get itself; the units such a unit is built from do not get it either (they are loaded while its interface is not compiled yet; with -B giving it to them would be a circular reference). Naming the units again is no duplicate.
  • Wildcards (uses UI.*) were considered and left out: the hiding order would not be in the source, and adding a unit to a folder would change what an unchanged program means.

Implementation

  • pmodules.pas: parsing (parseusesclause), connect_loaded_units pushes the passed-on units before the re-exporting one and registers them as used units of the user (with a unit symbol for qualified names); addprojectuses for units and programs.
  • fmodule.pas: tused_unit.reexport / via_reexport / via_project; allunitsused hint rules.
  • fppu.pas, entfile.pas, ppu.pas: interface entry ibreexportunits (counted in the interface crc), PPU long version 49.
  • options.pas, globals.pas: --project-uses (the options are read more than once, units are added once).
  • msg/errore.msg: parser_e_reexport_uses_in_implementation (03448).
  • Docs: unleashed/docs/uses-export.md, index entry in unleashed/docs/README.md.

Test plan

  • qualification/compiler-uses-export/run_gate.py: 8 cases (re-export and name order, per-unit export, the implementation error, no unused-unit hint, recompilation of a user when a passed-on unit changes, project uses with and without -B), on a toolchain built from this branch with build.ps1 compiler.
  • Used by an application platform (uses Lumi / lumi.json "uses"), its full test suite passing.

🤖 Generated with Claude Code

…ses)

uses export (unleashed mode): a unit passes units of its interface uses
clause on to the units that use it, so one name brings a whole set
(C# global using, Rust pub use, TS export *).

  unit Lumi;
  interface
  uses export UI.Forms, UI.StdCtrls, Data.Window;

- "export" right after "uses" covers the clause; before a later unit, that
  unit only. In the implementation uses clause it is error 03448.
- A user sees the passed-on units as if they stood right before the
  re-exporting unit: its own names win, later units of the user win over
  both, and every passed-on unit stays reachable by its qualified name.
  Transitive. Naming a passed-on unit again is no duplicate.
- The user records the passed-on units as used units (their crc goes into
  its ppu), so a change of their interface recompiles it.
- No "unit not used" hint for a unit used only for what it passes on, nor
  for the passed-on units inside the re-exporting unit.
- PPU: interface entry ibreexportunits (counted in the interface crc);
  PPU long version 49.

--project-uses=A,B: every unit and program of the run uses A and B, as if
they stood first in its uses clause (-Fa covers programs only). A unit that
is one of them does not get itself; the units such a unit is built from do
not get it either (they are loaded while its interface is not compiled
yet; giving it to them would be a circular reference with -B). Naming them
again is no duplicate.

Wildcards (uses UI.*) were considered and left out: the hiding order would
not be in the source, and adding a unit to a folder would change what an
unchanged program means.

qualification/compiler-uses-export: re-export, per-unit export, the
implementation error, no unused hint, recompilation, project uses with and
without -B. Documentation: unleashed/docs/uses-export.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant